/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.itintegration.catalogue.gui.service.view.product;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.cdi.CdiCamelContext;
import se.sll.itintegration.catalogue.gui.camel.cdi.CamelRoute;
import se.sll.itintegration.catalogue.gui.data.ProductView;
import se.sll.service.catalogue.common.exception.ResourceNotFoundException;
import se.sll.service.catalogue.common.exception.ServiceCatalogueException;
import se.sll.service.catalogue.common.exception.ValidationException;

/**
 *
 * @author khaleddaham
 */
@Path("/view/product")
@Slf4j
@Stateless
public class ProductViewService {

    @Inject
    private CdiCamelContext camelCtx;

    @GET
    @Produces("application/json; charset=UTF-8")
    @Path("/")
    public ProductView getProductView(@Context SecurityContext sc) throws ValidationException, ResourceNotFoundException, ServiceCatalogueException {
        log.trace("getProductView() ENTER");
        ProducerTemplate template = camelCtx.createProducerTemplate();
        ProductView view = (ProductView) template.sendBodyAndProperty(CamelRoute.GET_PRODUCT_VIEW, ExchangePattern.InOut,
                null, "sc", sc);
        log.trace("getProductView() ENTER");
        return view;
    }
}
